<script setup>
import { ref, onMounted, computed } from 'vue'
import { useRoute } from 'vue-router'
import { commodityGetListService } from '@/api/commodity'
const route = useRoute()
const proList = ref([])

const querySearch = computed(() => route.query.search) 
const cSortId = computed(() => route.query.cSortId) 
const searchParam = ref({
  name: querySearch.value,
  cSortId
})
console.log("---" + route.query.search);
const getGoodsList = async () => {
  const { data : { list }} = await commodityGetListService(searchParam.value)
  proList.value = list
console.log("6666666666666" , proList.value);
}
getGoodsList()


</script>

<template>
  <div class="search">
    <van-nav-bar fixed title="商品列表" left-arrow @click-left="$router.go(-1)" />

    <van-search
      readonly
      shape="round"
      background="#ffffff"
      show-action
      @click="$router.push('/search')"
       :value="querySearch || '搜索商品'"
    >
      <template #action>
        <van-icon class="tool" name="apps-o" />
      </template>
    </van-search>

    <!-- 排序选项按钮 -->
    <div class="sort-btns">
      <div class="sort-item">综合</div>
      <div class="sort-item">销量</div>
      <div class="sort-item">价格 </div>
    </div>

    <div class="goods-list">
      <GoodsItem v-for="item in proList" :item="item" :key="item"></GoodsItem>
    </div>
  </div>
</template>

<style lang="less" scoped>
.search {
  padding-top: 46px;
  ::v-deep .van-icon-arrow-left {
    color: #333;
  }
  .tool {
    font-size: 24px;
    height: 40px;
    line-height: 40px;
  }

  .sort-btns {
    display: flex;
    height: 36px;
    line-height: 36px;
    .sort-item {
      text-align: center;
      flex: 1;
      font-size: 16px;
    }
  }
}

// 商品样式
.goods-list {
  background-color: #f6f6f6;
}
</style>